#!/usr/bin/env bash
set -e
hook=.git/hooks/commit-msg
echo "1. 检查钩子是否存在"
[ -f "$hook" ] || { echo "❌ 钩子文件不存在"; exit 1; }
echo "2. 检查可执行权限"
[ -x "$hook" ] || { echo "❌ 没有执行权限"; chmod +x "$hook"; }
echo "3. 检查换行符"
file "$hook" | grep -q "CRLF" && { echo "❌ 含 CRLF，需转 LF"; dos2unix "$hook"; }
echo "4. 检查 shebang"
head -1 "$hook" | grep -Eq '^#!' || { echo "❌ 缺少 shebang"; exit 1; }
echo "5. 模拟 commit-msg 调用"
echo "feat: test" > /tmp/COMMIT_EDITMSG
"$hook" /tmp/COMMIT_EDITMSG && echo "✅ 钩子通过" || echo "❌ 钩子拒绝"


